
from sqlalchemy import BigInteger, Column, Integer, String, Text
from app.entity.baseModal import BaseModal
from sqlalchemy.orm import Mapped,mapped_column,declarative_base, relationship,sessionmaker

from app.entity.user import User

class ProjectMessage(BaseModal):
    __tablename__="jz_project_message"
    _idGeneratorType="db"
    _fieldIgnore = []
    projectId:Mapped[int]=mapped_column(BigInteger(),name="project_id")
    receiver:Mapped[int]=mapped_column(BigInteger())
    message:Mapped[str]=mapped_column(Text())
    sender:Mapped[int]=mapped_column(BigInteger())
    toPage:Mapped[str]=mapped_column(String(500),name="to_page")
    title:Mapped[str]=mapped_column(String(500))
    reader:Mapped[str]=mapped_column(Text())

    def getSenderDescAttr(self):
        user=User().query().where(User.id==self.sender).with_entities(User.nickname).first()
        return user.nickname if user!=None else ""
    
    def getReceiverDescAttr(self):
        user=User().query().where(User.id==self.receiver).with_entities(User.nickname).first()
        return user.nickname if user!=None else ""